package com.zut.yunxi.yunxi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.zut.yunxi.yunxi.dao.UserDao;
import com.zut.yunxi.yunxi.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SpringDataUserDetailsService implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String s)  {



        QueryWrapper<UserEntity> queryWrapper=new QueryWrapper<UserEntity>().eq("username",s);
        UserEntity userEntity = userDao.selectOne(queryWrapper);
        if(userEntity==null)
            throw  new UsernameNotFoundException("找不到");
        else
        {
            System.out.println(userEntity);
            UserDetails userDetails=null;
          userDetails = User.withUsername(s).password(userEntity.getPassword()).authorities("p1").build();
            return userDetails;
        }

    }
}
